package com.example.user.userinfo

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.ToastUtils
import com.example.lib_base.mvvm.BaseActivity
import com.example.user.R
import com.example.user.databinding.ActivityUserInfoBinding

@Route(path = "/user/UserInfoActivity")
class UserInfoActivity : BaseActivity<ActivityUserInfoBinding,UserInfoViewModel>() {
    override fun initData() {
        viewModel.userInfoSuccess.observe(this){
            if(it.code==200){
                binding.userInfo = it.data
            }else{
                ToastUtils.showLong(it.message)
            }
        }
        viewModel.userInfoFail.observe(this){
            ToastUtils.showLong(it)
        }
        //点击退出登录
        binding.btnLogout.setOnClickListener {
            //根据实际情况判断 是否需要接口的退出登录
            SPUtils.getInstance().clear()
            ARouter.getInstance().build("/user/LoginActivity").navigation()
        }
        //点击修改密码 跳转到修改密码界面
        binding.btnUpdatepwd.setOnClickListener {
            ARouter.getInstance().build("/user/UpdatePwdActivity").navigation()
        }
    }

    override fun initView() {
        viewModel.userInfo()
    }

    override fun getViewModel(): Class<UserInfoViewModel>  = UserInfoViewModel::class.java

    override fun getLayout(): Int  = R.layout.activity_user_info

}